#include "ukuistylehelper.h"
//#include "../waylandhelper.h"
//#include "ukui-decoration-manager.h"
#include <QWidget>
#include <QGuiApplication>
#include "../../kysdk-qtwidgets/xatom-helper.h"

namespace kdk
{

static UkuiStyleHelper *global_instance = nullptr;

UkuiStyleHelper *UkuiStyleHelper::self()
{
    if (global_instance)
        return global_instance;
    else {
        global_instance = new UkuiStyleHelper();
        return global_instance;
    }
}

void UkuiStyleHelper::removeHeader(QWidget *widget)
{
    if (!widget)
        return;
    QString platform = QGuiApplication::platformName();
    if (platform.startsWith(QLatin1String("wayland"), Qt::CaseInsensitive)) {
        m_widget = widget;
        m_widget->installEventFilter(this);
    } else {
        MotifWmHints hints1;
        hints1.flags = MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS;
        hints1.functions = MWM_FUNC_ALL;
        hints1.decorations = MWM_DECOR_BORDER;
        XAtomHelper::getInstance()->setWindowMotifHint(widget->winId(), hints1);
    }
}
//#include "../../kysdk-waylandhelper/ukuistylehelper/ukui-decoration-manager.h"
bool UkuiStyleHelper::eventFilter(QObject *obj, QEvent *ev)
{
    if (obj == m_widget && (ev->type() == QEvent::PlatformSurface || ev->type() == QEvent::Show || ev->type() == QEvent::Paint)) {
//            UKUIDecorationManager::getInstance()->removeHeaderBar(m_widget->windowHandle());
    }
    return QObject::eventFilter(obj, ev);
}

UkuiStyleHelper::UkuiStyleHelper() {}

} // namespace kdk
